package com.cws.project.cws.resit.service.impl;

import java.util.*;

import com.cws.common.utils.DateUtils;
import com.cws.common.utils.StringUtils;
import com.cws.common.utils.text.Convert;
import com.cws.project.cws.course.domain.Course;
import com.cws.project.cws.course.service.ICourseService;
import com.cws.project.cws.resit.domain.CourseResit;
import com.cws.project.cws.resit.mapper.CourseResitMapper;
import com.cws.project.cws.resit.service.ICourseResitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 补考信息Service业务层处理
 *
 * @author xyl
 * @date 2022-03-22
 */
@Service
public class CourseResitServiceImpl implements ICourseResitService {
    @Autowired
    private CourseResitMapper courseResitMapper;
    @Autowired
    private ICourseService courseService;

    /**
     * 查询补考信息
     *
     * @param resitId 补考信息ID
     * @return 补考信息
     */
    @Override
    public CourseResit selectCourseResitById(Long resitId) {
        return courseResitMapper.selectCourseResitById(resitId);
    }

    /**
     * 查询补考信息列表
     *
     * @param courseResit 补考信息
     * @return 补考信息
     */
    @Override
    public List<CourseResit> selectCourseResitList(CourseResit courseResit) {
        List<CourseResit> courseResits = courseResitMapper.selectCourseResitList(courseResit);
//        Map<Long, Double> map = new LinkedHashMap<>();
//        if (courseResit.getStudentId() != null) {
//            Course course = new Course();
//            course.setStudentId(courseResit.getStudentId());
//            List<Course> courses = courseService.selectStudentCourseList(course);
//            for (Course cours : courses) {
//                if (StringUtils.equals(cours.getIsCourseEnd(), "是")) {
//                    Double score = cours.getScore();
//                    if (score < 60) {
//                        map.put(cours.getClazzId(), score);
//                    }
//                }
//            }
//            if(map.size() == 0){
//                return courseResits;
//            }else{
//                for (CourseResit resit : courseResits) {
//                    Double aDouble = map.get(resit.getCourseId());
//                    if(aDouble != null){
//                        resit.setScore(aDouble);
//                    }
//                }
//            }
//        }
        return courseResits;
    }

    /**
     * 新增补考信息
     *
     * @param courseResit 补考信息
     * @return 结果
     */
    @Override
    public int insertCourseResit(CourseResit courseResit) {
        courseResit.setCreateTime(DateUtils.getNowDate());
        return courseResitMapper.insertCourseResit(courseResit);
    }

    /**
     * 修改补考信息
     *
     * @param courseResit 补考信息
     * @return 结果
     */
    @Override
    public int updateCourseResit(CourseResit courseResit) {
        courseResit.setUpdateTime(DateUtils.getNowDate());
        return courseResitMapper.updateCourseResit(courseResit);
    }

    /**
     * 删除补考信息对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCourseResitByIds(String ids) {
        return courseResitMapper.deleteCourseResitByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除补考信息信息
     *
     * @param resitId 补考信息ID
     * @return 结果
     */
    @Override
    public int deleteCourseResitById(Long resitId) {
        return courseResitMapper.deleteCourseResitById(resitId);
    }

    @Override
    public CourseResit selectCourseResitByCourseId(Long courseId) {
        return courseResitMapper.selectCourseResitByCourseId(courseId);
    }
}
